<template>
	<view class="wrap">
		<u-form style="background: #fff;padding-left: 30rpx" :model="model" :rules="rules" ref="uForm"
				:errorType="errorType">
			<u-form-item label="抖音号" label-width="200" prop="douyin">
				<u-input placeholder="请输入抖音号名" v-model="model.douyin" type="text"></u-input>
			</u-form-item>

		</u-form>
		<view class="note">
			<view>请填写真实的正确的抖音号，否则将导致任务失败，请仔细核实信息</view>
			<view>抖音信息只能修改一次，请核实无误后提交</view>
		</view>
		<view style="margin-top: 60rpx;">
			<u-button @click="submit" style="background-color: #fec762" :plain="false" :ripple="true" type="primary">提交
			</u-button>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		let that = this;
		return {
			model: {
				douyin:"",
			},
			rules: {
				douyin:[
					{
						required: true,
						message: '请输入抖音号',
						trigger: ['change','blur'],
					}
				],
			},
			errorType: ['message'],
		};
	},
	onLoad() {
		this.$request.post("/member/getMember", {
			dataType: 'json',
			responseType: 'text'
		})
		.then(res => {
			let user = res.data.json;
			if(user.douyin){
				this.model.douyin = user.douyin;
			}
		})
	},
	onReady() {
		this.$refs.uForm.setRules(this.rules);
	},
	methods: {
		async submit() {
			await this.$refs.uForm.validate(valid => {
				if (valid) {
					uni.showLoading({
						title:"正在提交",
						mask:true
					})
					this.$request.post("/member/setDouyin", {
						data:{
							douyin:this.model.douyin
						},
						dataType: 'json',
						responseType: 'text'
					})
					.then(res => {
						uni.hideLoading();
						this.$api.msg("提交成功");
					})
					.catch(error => {
						uni.hideLoading();
					});
				}
			});
		},
	}
};
</script>

<style scoped lang="scss">
.wrap {
	padding: 30rpx;
}

.agreement {
	display: flex;
	align-items: center;
	margin: 40rpx 0;

	.agreement-text {
		padding-left: 8rpx;
		color: $u-tips-color;
	}
}
.note{
	font-size: 26rpx;
	padding: 30rpx 0;
	line-height: 50rpx;
}
</style>
